import {
  promises as fs,
} from 'node:fs'

import presetRemToPx from '@unocss/preset-rem-to-px'

import {
  defineConfig,
  presetAttributify,
  presetIcons,
  presetUno,
  transformerAttributifyJsx,
  transformerCompileClass,
  transformerDirectives,
  transformerVariantGroup,
} from 'unocss'

export default defineConfig({
  shortcuts: [
    {
      'req': 'before-content-[quoted:*] before-text-red before-m-r-0.25',
      'bg-pr': 'bg-[var(--sy-color-primary)]',
      'text-pr': 'text-[var(--sy-color-primary)]',
      'hover-text-pr': 'hover:text-[var(--sy-color-primary)]',
    },
  ],
  presets: [
    presetUno(),
    presetRemToPx(),
    presetIcons({
      warn: true,
      collections: {
        iconfont: async iconName => fs.readFile(`./src/assets/iconfont/${iconName}.svg`, 'utf8'),
      },
    }),
    presetAttributify({
      prefix: 'un-',
      prefixedOnly: true,
    }),
  ],
  transformers: [
    transformerCompileClass(),
    transformerDirectives(),
    transformerVariantGroup(),
    transformerAttributifyJsx(),
  ],
})
